package ar.com.ctrln.persistence.dao.ticket;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ar.com.ctrln.persistence.dao.AbstractHibernateDao;
import ar.com.ctrln.persistence.model.insumo.Insumo;
import ar.com.ctrln.persistence.model.ticket.Ticket;
import ar.com.ctrln.persistence.model.ticket.TipoTicket;

@Repository("ticketDao")
public class HibernateTicketDao extends AbstractHibernateDao<Ticket> implements TicketDao {

	@Override
	public Ticket findTicketById(long id) {
		Query q = getSession().createQuery("from Ticket t where t.id = ?");
		q.setParameter(0, id);
		return (Ticket) q.uniqueResult();
	}

	@Override
	public Ticket findTicketByTipo(TipoTicket tipo) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Ticket> ticketsByEmisor(long id) {
		Query q = getSession().createQuery("from Ticket i where i.organizacion.id = ? order by i.fechaAlta desc");
		q.setParameter(0, id);
		return (List<Ticket>)q.list();
	}
	
	@Transactional(readOnly=true)
	public List<Ticket> ticketsOrder (){
		Query q = getSession().createQuery("from Ticket i order by i.fechaAlta desc");
		return (List<Ticket>)q.list();
		
	}

}
